package member

import (
	"lao-a/helper"
	"lao-a/models/model"
)

const (
	LEVEL_NORMAL = iota + 1
	LEVEL_NOTUSE
)

// 获取所有的级别
func (m *DAO) GetAllNemLvl(sort ...string) ([]model.TdLevel, error) {
	sortBy := "asc"

	if len(sort) > 0 {
		sortBy = sort[0]
	}

	var lvl []model.TdLevel
	if sortBy == "asc" {
		if err := m.db.Asc("weight").Find(&lvl); err != nil {
			return lvl, helper.LogError("获取所有会员等级失败", err)
		}
	} else {
		if err := m.db.Desc("weight").Find(&lvl); err != nil {
			return lvl, helper.LogError("获取所有会员等级失败", err)
		}
	}

	return lvl, nil
}

// GetMemberNormalLvl 获取会员类型
func (m *DAO) GetMemberNormalLvl() ([]model.TdLevel, error) {
	var lvls []model.TdLevel

	if err := m.db.Where("status=?", LEVEL_NORMAL).Asc("weight").Find(&lvls); err != nil {
		return nil, helper.LogError("查询会员类型出错", err)
	}

	return lvls, nil
}
